{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "12aa9553-7d5e-43db-b8d3-93e8e040fb4d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[5.65685425 7.39923721 0.22414387 3.33677403 7.77817459]\n",
      "[-2.44948974 -1.60368225 -4.44140056 -0.41361256  1.22474487]\n",
      "[ 3.  7.  1.  1. -2.  5.  4.  6.]\n"
     ]
    }
   ],
   "source": [
    "import pywt\n",
    "x = [3, 7, 1, 1, -2, 5, 4, 6]\n",
    "cA, cD = pywt.dwt(x, 'db2')\n",
    "print(cA)\n",
    "print(cD)\n",
    "print(pywt.idwt(cA, cD, 'db2'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "adbc099e-4e3b-4e82-b1e3-2561389c48f8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 4.38354585  3.80302657  7.31813271 -0.58565539  4.09727044  7.81994027]\n",
      "[-1.33068221 -2.78795192 -3.16825651 -0.67715519 -0.09722957 -0.07045258]\n"
     ]
    }
   ],
   "source": [
    "w = pywt.Wavelet('sym3')\n",
    "cA, cD = pywt.dwt(x, wavelet=w, mode='constant')\n",
    "print(cA)\n",
    "print(cD)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "80dded2f-6a1c-43da-bd67-7796f4f55185",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# int() is for normalizing Python integers and long integers for documentation tests\n",
    "int(pywt.dwt_coeff_len(data_len=len(x), filter_len=w.dec_len, mode='symmetric'))\n",
    "int(pywt.dwt_coeff_len(len(x), w, 'symmetric'))\n",
    "len(cA)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "08d7de2e-c643-4a8b-8e7b-60588684f65a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['zero', 'constant', 'symmetric', 'periodic', 'smooth', 'periodization', 'reflect', 'antisymmetric', 'antireflect']\n",
      "[ 1.  1. -2.  5.]\n",
      "[ 3.  7.  1.  1. -2.  5.  4.  6.]\n",
      "[ 1.19006969  1.54362308  0.44828774 -0.25881905  0.48296291  0.8365163 ]\n",
      "[ 1.19006969  1.54362308  0.44828774 -0.25881905  0.48296291  0.8365163 ]\n",
      "[ 0.57769726 -0.93125065  1.67303261 -0.96592583 -0.12940952 -0.22414387]\n",
      "[ 0.57769726 -0.93125065  1.67303261 -0.96592583 -0.12940952 -0.22414387]\n"
     ]
    }
   ],
   "source": [
    "print(pywt.Modes.modes)\n",
    "cA, cD = pywt.dwt(x, wavelet=w, mode='periodization')\n",
    "print(pywt.idwt(cA, cD, 'sym3', 'symmetric')) # invalid mode\n",
    "print(pywt.idwt(cA, cD, 'sym3', 'periodization'))\n",
    "print(pywt.idwt([1,2,0,1], None, 'db2', 'symmetric'))\n",
    "print(pywt.idwt([1, 2, 0, 1], [0, 0, 0, 0], 'db2', 'symmetric'))\n",
    "print(pywt.idwt(None, [1, 2, 0, 1], 'db2', 'symmetric'))\n",
    "print(pywt.idwt([0, 0, 0, 0], [1, 2, 0, 1], 'db2', 'symmetric'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "c8ca6516-f81d-4b0b-a6d5-424523a87d1f",
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "At least one coefficient parameter must be specified.",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[0;32m/tmp/ipykernel_46826/3961068409.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpywt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0midwt\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'db2'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'symmetric'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;32m/usr/local/lib/python3.8/dist-packages/pywt/_dwt.py\u001b[0m in \u001b[0;36midwt\u001b[0;34m(cA, cD, wavelet, mode, axis)\u001b[0m\n\u001b[1;32m    239\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    240\u001b[0m     \u001b[0;32mif\u001b[0m \u001b[0mcA\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mNone\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0mcD\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 241\u001b[0;31m         raise ValueError(\"At least one coefficient parameter must be \"\n\u001b[0m\u001b[1;32m    242\u001b[0m                          \"specified.\")\n\u001b[1;32m    243\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mValueError\u001b[0m: At least one coefficient parameter must be specified."
     ]
    }
   ],
   "source": [
    "print(pywt.idwt(None, None, 'db2', 'symmetric'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "5def7024-6e60-4e2d-92c5-52f88f945256",
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "Coefficients arrays must have the same size.",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[0;32m/tmp/ipykernel_46826/3061334629.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpywt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0midwt\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m2\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m3\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m4\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m5\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m2\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m3\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m4\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'db2'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'symmetric'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      2\u001b[0m \u001b[0mpywt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0midwt\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m4\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;36m4\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'db4'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'symmetric'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      3\u001b[0m \u001b[0mint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpywt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdwt_coeff_len\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mpywt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mWavelet\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'db4'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdec_len\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'symmetric'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.8/dist-packages/pywt/_dwt.py\u001b[0m in \u001b[0;36midwt\u001b[0;34m(cA, cD, wavelet, mode, axis)\u001b[0m\n\u001b[1;32m    286\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    287\u001b[0m     \u001b[0;32mif\u001b[0m \u001b[0mndim\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 288\u001b[0;31m         \u001b[0mrec\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0midwt_single\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcA\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcD\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mwavelet\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmode\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    289\u001b[0m     \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    290\u001b[0m         \u001b[0mrec\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0midwt_axis\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcA\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcD\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mwavelet\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmode\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0maxis\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32mpywt/_extensions/_dwt.pyx\u001b[0m in \u001b[0;36mpywt._extensions._dwt.idwt_single\u001b[0;34m()\u001b[0m\n",
      "\u001b[0;32mpywt/_extensions/_dwt.pyx\u001b[0m in \u001b[0;36mpywt._extensions._dwt.idwt_single\u001b[0;34m()\u001b[0m\n",
      "\u001b[0;31mValueError\u001b[0m: Coefficients arrays must have the same size."
     ]
    }
   ],
   "source": [
    "print(pywt.idwt([1, 2, 3, 4, 5], [1, 2, 3, 4], 'db2', 'symmetric'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "a4a67e3b-1330-4024-a4f1-68a0be367f63",
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "Invalid coefficient arrays length for specified wavelet. Wavelet and mode must be the same as used for decomposition.",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[0;32m/tmp/ipykernel_46826/3736668752.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mpywt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0midwt\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m4\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;36m4\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'db4'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'symmetric'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;32m/usr/local/lib/python3.8/dist-packages/pywt/_dwt.py\u001b[0m in \u001b[0;36midwt\u001b[0;34m(cA, cD, wavelet, mode, axis)\u001b[0m\n\u001b[1;32m    286\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    287\u001b[0m     \u001b[0;32mif\u001b[0m \u001b[0mndim\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 288\u001b[0;31m         \u001b[0mrec\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0midwt_single\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcA\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcD\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mwavelet\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmode\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    289\u001b[0m     \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    290\u001b[0m         \u001b[0mrec\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0midwt_axis\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcA\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcD\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mwavelet\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmode\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0maxis\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32mpywt/_extensions/_dwt.pyx\u001b[0m in \u001b[0;36mpywt._extensions._dwt.idwt_single\u001b[0;34m()\u001b[0m\n",
      "\u001b[0;32mpywt/_extensions/_dwt.pyx\u001b[0m in \u001b[0;36mpywt._extensions._dwt.idwt_single\u001b[0;34m()\u001b[0m\n",
      "\u001b[0;31mValueError\u001b[0m: Invalid coefficient arrays length for specified wavelet. Wavelet and mode must be the same as used for decomposition."
     ]
    }
   ],
   "source": [
    "pywt.idwt([1,2,4], [4,1,3], 'db4', 'symmetric')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "189befe5-4531-4419-b32f-98134cc24bc6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "int(pywt.dwt_coeff_len(1, pywt.Wavelet('db4').dec_len, 'symmetric'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "db47c4a2-135e-4ef0-8281-7055846b1b10",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
